using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace UM_Model.Models.Mapping
{
    public class DocumentMap : EntityTypeConfiguration<Document>
    {
        public DocumentMap()
        {
            // Primary Key
            this.HasKey(t => t.DocumentID);

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(50);

            this.Property(t => t.Link)
                .HasMaxLength(200);

            // Table & Column Mappings
            this.ToTable("Documents");
            this.Property(t => t.DocumentID).HasColumnName("DocumentID");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Catalog).HasColumnName("Catalog");
            this.Property(t => t.Link).HasColumnName("Link");
            this.Property(t => t.IsEnable).HasColumnName("IsEnable");

            // Relationships
            this.HasOptional(t => t.DocumentsCatalog)
                .WithMany(t => t.Documents)
                .HasForeignKey(d => d.Catalog);

        }
    }
}
